package danran.dfs;

import java.util.*;

/**
 * @Classname Main2
 * @Description TODO
 * @Date 2021/8/28 19:06
 * @Created by ASUS
 */
public class Main2 {

    public static int[] getData() {
        Scanner scanner = new Scanner(System.in);
        return Arrays.stream(scanner.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
    }

    public static List<List<Integer>> solution() {
        int[] data = getData();
        List<Stack<Integer>> stacks = new ArrayList<>();
        for (int i = 0; i < data.length; i++) {
            int cur = data[i];
            boolean added = false;
            if (stacks.size() == 0) stacks.add(new Stack<>());
            for (Stack<Integer> stack : stacks) {
                if (stack.isEmpty()) {
                    stack.push(cur);
                    added = true;
                    break;
                } else {
                    if (cur < stack.peek()) {
                        stack.push(cur);
                        added = true;
                        break;
                    }
                }
            }
            if (!added) {
                Stack<Integer> newStack = new Stack<>();
                newStack.add(cur);
                stacks.add(newStack);
            }
        }
        List<List<Integer>> ans = new ArrayList<>();
        for (Stack<Integer> stack : stacks) {
            ans.add(new ArrayList<>(stack));
        }
        return ans;
    }

    public static void main(String[] args) {
        List<List<Integer>> solution = solution();
        System.out.println(solution.size());
        for (List<Integer> sol : solution) {
            for (int i = 0; i < sol.size(); i++) {
                System.out.print(sol.get(i));
                if (i != sol.size() - 1) System.out.print(",");
            }
            System.out.println();
        }
    }

}
